package com.demo0212;

/**
 * Created by cc
 * Description:
 * User: CZH
 * Date: 2023-02-12
 * Time: 19:57
 */
public class Test01 {
    public static void main(String[] args) {
        int[] nums = {15,11,2,7};
        int t = 10;
        if (twoSum(nums, t) != null) {
            for (int data : twoSum(nums, t)) {
                System.out.print(data + " ");
            }
        }
        System.out.println();
    }
    public static int[] twoSum(int[] nums, int target) {
        int[] arr = new int[2];
        int len = nums.length;
        for (int i = 0; i < len; i++) {
            // 将t-nums
            int tmp = target - nums[i];
            // 后将结果和后面的元素相比
            if (i+1 == len) return null;
            for (int j = i + 1; j < len; j++) {
                if (tmp == nums[j]) {
                    arr[0]=i;
                    arr[1]=j;
                    return arr;
                }
            }
        }
        return null;
    }
}
